package com.example.netty.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

//这是个ChannelOutboundHandler
public class MyLongToByteEncoder extends MessageToByteEncoder<Long> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Long aLong, ByteBuf byteBuf) throws Exception {
        System.out.println("编码中。。。。");
        //Long实现了Serializable,在执行byteBuf的writeLong方法时就可以进行java的序列化转成二进制流
        byteBuf.writeLong(aLong);
    }
}
